#include<bits/stdc++.h>
using namespace std;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        int n,m,l,V,d[100005],v[100005],a[100005],p[100005],ans=0;
        cin>>n>>m>>l>>V;
        for(int i=0;i<n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=0;i<m;i++){
            cin>>p[i];
        }
        for(int i=0;i<n;i++){
            if(a[i]==0){
                if(v[i]>V&&p[m-1]>=d[i]){
                    ans++;
                }
            }
            if(a[i]>0){
                if(p[m-1]>=d[i]){
                    if(sqrt(v[i]*v[i]+2*a[i]*(p[m-1]-d[i]))>V){
                        ans++;
                    }
                }
            }
        }
        cout<<ans<<' ';
        if(ans==0){
            cout<<m<<endl;
        }else{
            cout<<m-1<<endl;
        }
    }
    return 0;
}
